# -*- coding: utf-8 -*-
"""
date: Fri Dec 14 14:03:21 2018
python: Anaconda 3.6.5
author: kanade
email: kanade@blisst.cn
"""
import numpy as np
import matplotlib.pyplot as mp


# 生成数据
n = 1000
x = np.linspace(0, 8 * np.pi, n)
sin_y = np.sin(x)
cos_y = np.cos(x / 2) / 2
# 创建图形窗口
mp.figure('Fill', facecolor='lightgray')
# 设置窗口标题
mp.title('Fill', fontsize=20)
# 设置坐标轴标签
mp.xlabel('x', fontsize=14)
mp.ylabel('y', fontsize=14)
# 设置刻度参数
mp.tick_params(labelsize=10)
# 设置网格线型
mp.grid(linestyle=':')
# 绘制曲线
mp.plot(x, sin_y, c='dodgerblue',
        label=r'$y=sin(x)$')
mp.plot(x, cos_y, c='orangered',
        label=r'$y=\frac{1}{2}cos(\frac{x}{2})$')
# 绘制填充区域
mp.fill_between(x, cos_y, sin_y, cos_y < sin_y,
                color='dodgerblue', alpha=0.5)
mp.fill_between(x, cos_y, sin_y, cos_y > sin_y,
                color='orangered', alpha=0.5)
# 绘制图例
mp.legend()
# 显示图形
mp.show()
